package oj.hot100;

public class 打家劫舍 {
    //动态规划,时间和空间都是O(n)
    public int rob(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n+2];
        for(int i = 2;i < n+2;i++) {
            dp[i] = Math.max(dp[i-2]+nums[i-2],dp[i-1]);
        }
        return dp[n+1];
    }
}
